<?= flash() ?? ''; ?>

<div class="breadcrumb d-flex align-items-center px-3 js-scroll">
    <div class="btn btn-icon me-4 js-back" aria-label="返回" role="button" tabindex="0">
        <i class="iconfont icon-left-arrow fs-20"></i>
    </div>
    <h2 class="w-100 fs-18 hand js-top"><span class="text-truncate"><?= $page_title ?? '' ?></span></h2>
</div>

<div class="d-flex justify-content-around p-4 text-muted fs-15 bg-light">
    <div>
        <p class="fs-32 text-dark"><?= isset($signed) ? '3' : '0'; ?></p>
        <span>今日已领</span>
    </div>
    <div>
        <p class="fs-32 text-dark"><?= isset($last_sign_time) ? $last_sign_time.'<span class="time-text">小时前</span>' : '-' ;?></p>
        <span>上次签到时间</span>
    </div>
    <div>
        <p class="fs-32 text-dark"><?= $user->golds ?? '-' ;?></p>
        <span>可用金币</span>
    </div>
</div>
<!-- <div class="wave-bar wave-bar-foot">
    <svg aria-hidden="true"><defs><pattern id="wave" x="50%" width="1440" height="64" patternUnits="userSpaceOnUse"><path d="M144 28.16C72.045 28.16 71.955 -9.34691e-07 0 0V64H1440V0C1368.05 -7.47754e-06 1367.95 28.16 1296 28.16C1224.05 28.16 1223.96 7.47754e-06 1152 0C1080.05 -7.47754e-06 1079.95 28.16 1008 28.16C936.045 28.16 935.955 0 864 0C792.045 0 791.955 28.16 720 28.16C648.045 28.16 647.955 3.73877e-06 576 0C504.045 -3.73877e-06 503.955 28.16 432 28.16C360.045 28.16 359.955 -3.73877e-06 288 0C216.045 3.73877e-06 215.955 28.16 144 28.16Z" fill="#fff"></path></pattern><mask id="wave-mask" maskUnits="objectBoundingBox"><rect x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect></mask></defs><rect x="0" y="0" width="100%" height="100%" fill="#f7f7f7" fill-opacity="1" mask="url(#wave-mask)"></rect></svg>
</div> -->
<div class="wave-bar mb-2">
    <svg viewBox="0 0 1152 73"><path d="M99.0331 0.252716C59.2655 0.284556 0 25.2197 0 25.2197V0.252716H99.0331C99.0585 0.252696 99.0839 0.252686 99.1093 0.252686C99.1538 0.252686 99.1982 0.252696 99.2427 0.252716H1152V73C1018.73 21.6667 957.818 24.4226 819.692 22.7693C672.54 21.008 573.085 73 427.919 73C308.414 73 218.068 0.307089 99.2427 0.252716H99.0331Z"></path></svg>
</div>

<nav class="nav nav-pills justify-content-center">
  <a  class="nav-link fs-18" id="my-reward" href="/reward">获得</a>
  <a class="nav-link fs-18" id="my-redeem" href="/reward/redeem">兑换</a>
  <a class="nav-link fs-18" id="my-levels" href="/reward/levels">等级</a>
</nav>

<div class="d-flex justify-content-around p-4 text-center">
    <div class="card bg-white p-4 border rounded me-4 text-dark text-decoration-none">
        <div class="placement fs-24 fw-bold">
            <span class="point <?= isset($signed) ? 'bg-success' : ''; ?>"></span> 3
        </div>
        <p><i class="iconfont icon-present fs-32 text-success"></i></p>
        <h3 class="fs-18 fw-bold">登录奖励</h3>
        <p class="fs-15 my-3">领取每日登录奖励，可用于发帖、回帖和下载附件。</p>
        <?php if(isset($signed)): ?>
            <button type="button" class="btn btn-secondary" disabled>已领取</button>
        <?php else: ?>
            <button type="submit" class="btn btn-secondary" id="<?= isset($signed) ? '' : 'js-sign'; ?>">点击领取</button>
        <?php endif ?>
    </div>
    <div class="card p-4 border rounded">
        <p><i class="iconfont icon-redpacket fs-32 text-danger"></i></p>
        <h3 class="fs-18 fw-bold">红包</h3>
        <p class="fs-15 mt-3">模块正在制作，敬请期待。</p>
    </div>
</div>

<div class="p-4">
    <h3 class="section-title mb-2 fs-18">登录奖励说明</h3>
    <p>每24小时可领取一次，每次 3 枚金币。</p>
    <p>发帖、回帖每次各需消耗 1 枚金币。</p>
</div>

<script>
document.addEventListener("DOMContentLoaded", (event) => {
    // 高亮当前链接
    highlightActiveLink('reward');
    document.getElementById('my-reward').classList.add('active');
    // 签到
    const signElement = document.getElementById("js-sign");
    if (signElement) {
        event.preventDefault(); // 阻止默认行为，比如链接跳转
        signElement.addEventListener('click', function() {
            fetch('/reward/sign/', {method: 'POST'})
            .then(response => response.json())
            .then(res => {
                if (res.status === 'success') {
                    toast.success(res.message);
                    document.querySelector('.point').classList.add('bg-success');
                    // 禁用按钮并显示"已领取"文字
                    signElement.textContent = '已领取';
                    signElement.disabled = true;
                    // 1.5秒后刷新页面
                    setTimeout(() => location.reload(), 1500);
                } else {
                    toast.error(res.message);
                }
            })
            .catch(error => console.error(error)); // 处理错误，避免被忽略。
        });
    }
});
</script>